home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d883.lha / BBBBS / BBBBS59.lha / rexx / ArcMsgs.rexx < prev    next >
OS/2 REXX Batch file  |  1993-04-11  |  8KB  |  318 lines

  1. /*       $VER: 5.8a ArcMsgs.rexx 11 Apr 1993 (11.4.93)
  2.   archives unread conference messages into file in users email
  3. copyright 1991-92-93 Richard Lee Stockton  FREELY DISTRIBUTABLE
  4. */
  5.  
  6. SIGNAL ON BREAK_C
  7. SIGNAL ON ERROR
  8. SIGNAL ON SYNTAX
  9. OPTIONS FAILAT 999999
  10.  
  11. PARSE ARG name' 'single_dir' '.
  12. IF STRIP(single_dir)='' THEN single_dir=0
  13. IF name='' THEN CALL GETOUT(20)
  14.  
  15. CALL CLOSE(STDOUT)
  16. CALL OPEN(STDOUT,'RAM:ArcMsgs.STDOUT','W')
  17.  
  18. figarg='s:CONFIG.BBS'
  19. IF ~EXISTS(figarg) THEN figarg='BBS:BBS_TEXT/CONFIG.BBS'
  20. x=OPEN(f,figarg,'R')
  21. IF x=0 THEN
  22.   DO
  23.     SAY 's:CONFIG.BBS and BBS:BBS/CONFIG.BBS are both missing!'
  24.     CALL GETOUT(21)
  25.   END
  26.  
  27. data.=''
  28. DO i=1 TO 33
  29.   data.i=READLN(f)
  30. END
  31. CALL CLOSE(f)
  32.  
  33. compos=POS('/*',data.1)
  34. IF compos>0 THEN data.1=LEFT(data.1,compos-1)
  35. bbsname = STRIP(data.1)
  36. sysop   = WORD(data.2,1)
  37. bbspath = WORD(data.6,1)
  38. IF ~EXISTS(bbspath) THEN
  39.   DO
  40.     SAY bbspath 'does not exist!'
  41.     CALL GETOUT(22)
  42.   END
  43. testchar=RIGHT(bbspath,1)
  44. IF testchar~='/' & testchar~=':' THEN bbspath=bbspath'/'
  45.  
  46. msgpath = WORD(data.7,1)
  47. IF ~EXISTS(msgpath) THEN
  48.   DO
  49.     SAY msgpath 'does not exist!'
  50.     CALL GETOUT(23)
  51.   END
  52. testchar=RIGHT(msgpath,1)
  53. IF testchar~='/' & testchar~=':' THEN msgpath=msgpath'/'
  54. msgpath=msgpath'MSG'
  55.  
  56. extension=WORD(data.32,1)
  57. arccom=data.33
  58. compos=POS('/*',data.33)
  59. IF compos>0 THEN data.33=LEFT(data.33,compos-1)
  60. arccom=STRIP(data.33)
  61. IF LEFT(extension,1)~='.' THEN
  62.   DO
  63.     extension='.lzh'
  64.     arccom='lharc -m m'
  65.   END
  66.  
  67. x=OPEN(f,bbspath'Users/'name,'R')
  68. IF x=0 THEN
  69.   DO
  70.     CALL DELAY(150)
  71.     x=OPEN(f,bbspath'Users/'name,'R')
  72.     IF x=0 THEN
  73.       DO
  74.         SAY name 'user file is missing!'
  75.         CALL GETOUT(24)
  76.       END
  77.   END
  78. data.=''
  79. DO i=1 TO 25
  80.   data.i=READLN(f)
  81. END
  82. CALL CLOSE(f)
  83. level=data.20%1
  84. lastread.=0
  85.  
  86. x=GETCLIP('BBS_'name'_22')
  87. IF x~='' THEN
  88.   DO
  89.     data.22=x
  90.     CALL SETCLIP('BBS_'name'_22')
  91.   END
  92.  
  93. msg.=''
  94. IF readopen(bbspath'Lists/Conferences') THEN
  95.   DO
  96.     DO i=1
  97.       line=READLN(f)
  98.       IF line='END' THEN BREAK
  99.       IF EOF(f) THEN BREAK
  100.       num=WORD(line,1)
  101.       IF DATATYPE(num,'N') THEN msg.num=WORD(line,2)
  102.     END
  103.     CALL CLOSE(f)
  104.   END
  105.  
  106. CALL SETCLIP('BBS_MSGS')
  107. CALL PRAGMA('P',-2)         /* lower the priority of this task */
  108.  
  109. subj='All New Conference Messages'
  110. IF single_dir>0 THEN subj=msg.single_dir' conference messages.'
  111.  
  112. IF GETCLIP('BBS_'name)='' THEN
  113.   DO
  114.     x=OPEN(f,bbspath'Numbers/LastMail','R')
  115.     IF x~=0 THEN lastm=READLN(f)+1
  116.     CALL CLOSE(f)
  117.     ADDRESS COMMAND 'ECHO >'bbspath'Numbers/LastMail 'lastm
  118.     x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  119.     IF x=0 THEN CALL GETOUT(26)
  120.     CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm)
  121.     CALL WRITELN(f,' From: BBBBS')
  122.     CALL WRITELN(f,'   To: 'name)
  123.     CALL WRITELN(f,' Subj: 'subj)
  124.     CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  125.     CALL WRITELN(f,LEFT('=',75,'='))
  126.     CALL WRITELN(f,'Here are the new messages you requested.')
  127.     CALL WRITELN(f,'The collection process was interrupted.')
  128.     CALL CLOSE(f)
  129.   END
  130.  
  131. filepath=bbspath'EmailFiles/'name
  132. CALL MAKEDIR(filepath)
  133. arcname=filepath'/BBBBS_'lastm
  134. IF GETCLIP('BBS_'name)~='' THEN arcname=filepath'/Messages'
  135. x=OPEN(a,arcname,'W')
  136. IF x=0 THEN CALL GETOUT(30)
  137.  
  138. CALL WRITELN(a,'= Custom archived for' name)
  139. CALL WRITELN(a,'=' bbsname  'conference messages to' DATE('W') DATE() TIME('C'))
  140. CALL WRITELN(a,'')
  141. CALL newmsgs()
  142.  
  143. CALL CLOSE(a)
  144. CALL DELAY(28)
  145. IF WORD(STATEF(arcname),2)<80 THEN CALL GETOUT(24)
  146. IF GETCLIP('BBS_'name)~='' THEN CALL GETOUT(0)
  147.  
  148. CALL PRAGMA('P',0)         /* normal priority */
  149. ADDRESS COMMAND arccom arcname||extension arcname
  150. x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  151. IF x=0 THEN CALL GETOUT(26)
  152. CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm||extension)
  153. CALL WRITELN(f,' From: BBBBS')
  154. CALL WRITELN(f,'   To: 'name)
  155. CALL WRITELN(f,' Subj: 'subj)
  156. CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  157. CALL WRITELN(f,LEFT('=',75,'='))
  158. CALL WRITELN(f,'Here are the archived new messages you requested.')
  159. CALL CLOSE(f)
  160. IF GETCLIP('BBS_level')~='' & WORD(GETCLIP('BBS_lastcaller'),1)=name THEN
  161.   DO
  162.     oldmess=GETCLIP('BBS_MESSAGE')
  163.     IF oldmess~='' THEN oldmess=oldmess||'0D0A'x
  164.     CALL SETCLIP('BBS_MESSAGE',oldmess||'Your archived messages are waiting in Email.')
  165.   END
  166. CALL GETOUT(0)
  167. EXIT
  168.  
  169.  
  170. /* Functions */
  171.  
  172. countcheck:
  173. PARSE ARG fname' '.
  174. IF ~readopen(fname) THEN RETURN(cknum)
  175. retval=STRIP(READLN(f))
  176. CALL CLOSE(f)
  177. IF ~DATATYPE(retval,'N') THEN retval=0
  178. RETURN(retval)
  179.  
  180.  
  181. newmsgs:
  182. IF single_dir>0 THEN
  183.   DO
  184.     msgdir=single_dir
  185.     CALL readmsg()
  186.     RETURN
  187.   END
  188. CALL WRITELN(a,'Scanning all Conferences for new messages..')
  189. DO newi=1 TO level
  190.   IF msg.newi='' THEN ITERATE newi
  191.   msgdir=newi
  192.   CALL readmsg()
  193. END
  194. RETURN
  195.  
  196.  
  197. readmsg:
  198. IF msg.msgdir='' | FIND(data.21,msgdir)>0 THEN RETURN;   /* sysop excluded */
  199. IF WORD(data.22,msgdir)=-1 THEN RETURN;  /*  user excluded */
  200. IF DATATYPE(WORD(data.22,msgdir),'N') THEN
  201.   lastread.msgdir=WORD(data.22,msgdir)
  202. IF STRIP(SHOWDIR(msgpath||msgdir))='' THEN RETURN
  203. lstwrt=countcheck(bbspath'Numbers/LastMessage'msgdir 0)
  204. frstwrt=countcheck(bbspath'Numbers/FirstMessage'msgdir 0)
  205. temp=''
  206. IF lastread.msgdir>=lstwrt THEN
  207.   DO
  208.     lastread.msgdir=lstwrt
  209.     RETURN
  210.   END
  211. CALL WRITELN(a,'Entering' msg.msgdir 'Message Conference..')
  212. dirname=msgpath||msgdir
  213. msglist.=0 /* set read to 0, unread to 1, and reply >=2 */
  214. firstmess=999999
  215. testlist=SHOWDIR(dirname)
  216. DO i=1 TO WORDS(testlist)
  217.   test=WORD(testlist,i)
  218.   IF test>lastread.msgdir THEN msglist.test=1
  219.   IF test<firstmess THEN firstmess=test
  220. END
  221. IF firstmess=999999 THEN firstmess=0
  222. CALL countcheck(bbspath'Numbers/FirstMessage'msgdir firstmess)
  223. msgstatus=1
  224. DO msgloop=1
  225.   lastreadnum=lastread.msgdir
  226.   DO WHILE msglist.lastreadnum=0 & lastreadnum<lstwrt
  227.     lastreadnum=lastreadnum+1
  228.   END
  229.   lastread.msgdir=lastreadnum
  230.   IF lastreadnum=lstwrt & msglist.lstwrt=0 THEN RETURN
  231.   DO mess=lastread.msgdir TO lstwrt+1
  232.     IF msglist.mess~=msgstatus THEN ITERATE mess
  233.     IF msgstatus>1 THEN CALL WRITELN(a,'Following the thread, level' msgstatus-1'.')
  234.     msglist.mess=0
  235.     arg=dirname'/'mess
  236.     IF ~EXISTS(arg) THEN
  237.       DO
  238.         CALL WRITELN(a,'Message number' mess 'is missing.')
  239.         ITERATE mess
  240.       END
  241.     IF ~readopen(arg) THEN ITERATE mess
  242.     firstline  = READLN(f)
  243.     secondline = READLN(f)
  244.     thirdline  = READLN(f)
  245.     forthline  = READLN(f)
  246.     CALL CLOSE(f)
  247.     IF WORDS(firstline)>2 THEN  /* if replies, change their num to >1 */
  248.       DO
  249.         thread=SUBSTR(firstline,WORDINDEX(firstline,4))
  250.         DO tindx=1 TO WORDS(thread)
  251.           test=WORD(thread,tindx)
  252.           IF msglist.test~=0 THEN msglist.test=msgstatus+1
  253.         END
  254.       END
  255.     CALL add_msg(arg)
  256.     IF thread~='' THEN
  257.        DO
  258.          thread=''
  259.          msgstatus=msgstatus+1
  260.        END
  261.   END
  262.   IF msgstatus>1 THEN msgstatus=msgstatus-1
  263. END
  264. RETURN
  265.  
  266.  
  267. readopen:
  268. PARSE ARG fname
  269. ok=OPEN(f,fname,'R')
  270. IF ok~=0 THEN RETURN(1)
  271. SAY fname 'failed to open for reading!'
  272. RETURN(0)
  273.  
  274.  
  275. readlines:
  276. CALL CLOSE(f)
  277. PARSE ARG tempname readstart .
  278. IF ~readopen(tempname) THEN RETURN(1)
  279. IF readstart<2 THEN lynes.=''
  280. DO ri=readstart
  281.   line=READLN(f)
  282.   IF EOF(f) THEN BREAK
  283.   lynes.ri=line
  284. END
  285. lynes.0=ri-1
  286. RETURN
  287.  
  288.  
  289. add_msg:
  290. ARG addname .
  291. x=OPEN(b,addname,'R')
  292. IF x=0 THEN SAY addname 'failed to open for reading!'
  293. ELSE
  294.   DO
  295.     data=READCH(b,65000)
  296.     CALL CLOSE(b)
  297.     CALL WRITECH(a,data)
  298.   END
  299. CALL WRITELN(a,'')
  300. CALL WRITELN(a,'')
  301. RETURN
  302.  
  303.  
  304. BREAK_C:
  305. SAY 'BREAK_C at line' SIGL
  306. CALL GETOUT(1)
  307.  
  308.  
  309. ERROR:
  310. SYNTAX:
  311. GETOUT:
  312. ARG errorout
  313. IF RC='RC' THEN RC=0
  314. IF errorout>0 | RC>0 THEN SAY 'Error:' errorout'  RC='RC'  SIGL='SIGL
  315. EXIT errorout
  316.  
  317. /* end of ArcMsgs.rexx */
  318.